package m1_simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接rabbitmq服务器
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.126.129");//rabbitmq服务器
        f.setPort(5672);//收发消息5672端口
        f.setUsername("admin");
        f.setPassword("admin");
        //建立tcp连接
        Connection connection = f.newConnection();
        //在连接里建立通道
        Channel channel = connection.createChannel();

        //定义目标队列
        channel.queueDeclare("helloworld",false,false,false,null);
        //发送消息
        channel.basicPublish("","helloworld",null,"Hello World".getBytes());
        System.out.println("消息已发送");
        channel.close();
        connection.close();
    }
}
